import { createSlice } from '@reduxjs/toolkit'

export const counterSlice = createSlice({
  name: 'person',
  initialState: {
   personList:[
    {
        id:1,
        name:'张三',
        code:'123456789012345678',
        state:false
    },
    {
        id:2,
        name:'李四',
        code:'123456789012345622',
        state:false
    },
    {
        id:3,
        name:'王五',
        code:'123456789012345633',
        state:false
    }
   ]
  },
  reducers: {
    //切换人员状态
    switchPerson(state,action){
        let item = state.personList.find(item=>item.id===action.payload.id)
        item.state =!item.state
    }
  }
})
// 每个 case reducer 函数会生成对应的 Action creators
export const { switchPerson } = counterSlice.actions

export default counterSlice.reducer